<template>
  <view class="content">
		<view class="banner-content">
			<view class="header-title">
				<text>曲阳县智慧城市</text>
				<uni-icons type="scan" color="#fff" size="24" style="position: absolute;right:20px;" @click="scanQrcode"></uni-icons>
			</view>
			<image class="banner-title" src="../static/images/index/banner-title.png"></image>
		</view>
		<view class="main-content">
			<view class="menu-content">
				<view class="menu-cell" v-for="(item,index) in mainMenuList" :key="index" @click="handleNav(item.navigateTo)">
					<view class="menu-main" :class="'menu-main-'+index"><image :src="item.iconUrl"></image></view>
					<view><text>{{item.name}}</text></view>
				</view>
			</view>
			<view class="menu-content">
				<view class="menu-cell no-circle" v-for="(item,index) in otherMenuList" :key="index" @click="handleNav(item.navigateTo)">
					<view style="overflow: hidden;">
						<image :src="item.iconUrl" style="" :class="item.className"></image>
					</view>
					<view><text>{{item.name}}</text></view>
				</view>
			</view>
			<view class="menu-content">
				<uni-notice-bar show-icon scrollable show-get-more background-color="#ffffff" color="#E11B0D"
						moreColor="#4F5466;"	style="margin-bottom: 0;padding: 3px;"	text="您有一条新的办件进度." />
			</view>
			
			<uni-section class="section-content" title="通知公告" title-font-size="16px">
				<template v-slot:right>
					<view style="font-size: 12px;line-height: 14px;color: rgba(53, 59, 80, 0.6);">更多</view>
				</template>
			</uni-section>
			<view class="menu-content" style="margin: 0 5%;">
				<view class="list-row">
					<view><image src="../static/images/index/img-notice.png"></image></view>
					<view class="list-row-right">
						<view class="title">注动能 提效能 全省12345政务热线业务培训会“干货”满满"</view>
						<text>2020-12-04</text>
					</view>
				</view>
			</view>
		</view>
  </view>
</template>

<script>
	import config from '@/config'
	import {getToken} from "@/utils/auth";
	import {authCode, qrcodeLogin} from '@/api/login'
	// import {xcInit} from "@/utils/xcMap.js"
	export default {
		data(){
			return {
				mainMenuList:[
				],
				otherMenuList:[
					{
						name:"更多",
						iconUrl:"../static/images/index/menu/icon-more.png",
						navigateTo:"work/index"
					}
				]
			}
	    },
		computed: {
			windowHeight() {
				return uni.getSystemInfoSync().windowHeight - 50
			}
		},
		onLoad: function() {
			this.getRouters();
		},
		methods:{
			handleNav(url){
				// console.log(getToken());
				// uni.showToast({
				// 	title:uni.getStorageSync("loginForm").username+"---"+uni.getStorageSync("loginForm").password
				// })
				if(url.indexOf("ydzf")!=-1){
					authCode(config.ssoAppId.zhzf).then(res=>{
						if(res.code == 200){
							// console.log(res.data);
							//跳转移动执法
							var main = plus.android.runtimeMainActivity();
							var Intent = plus.android.importClass('android.content.Intent');
							var intent = new Intent(main.getIntent());
							intent.setClassName(main, "com.chinacreator.qycgzf.app.MainActivity");
							// intent.setClassName(main, "com.chinacreator.h5.MainActivity");
							intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
							intent.putExtra("token", "Bearer "+getToken());
							intent.putExtra("code", res.data);
							intent.putExtra("entrance_code", "main-2");
							intent.putExtra("account", uni.getStorageSync("loginForm").username);
							intent.putExtra("password", uni.getStorageSync("loginForm").password);
							// intent.putExtra("account", "yydy");
							// intent.putExtra("password", "Qycg@2023");
							main.startActivity(intent);
						}
					});
				}else{
					this.$tab.navigateTo(url);
				}
			},
			getRouters(){
				//获取首页菜单
				let menuList = this.$store.state.user.routers[0];
				// console.log(JSON.stringify(menuList));
				let mainMenuList = menuList.children.filter((item,index) => {
					return index <4;
				})
				//按顺序取菜单
				this.mainMenuList = mainMenuList.map((item,i) => {
					return {
						"name":item.meta.title,
						"iconUrl":"../static/icons/"+item.meta.icon+".svg",
						"navigateTo":"../"+item.path,
						"className":"menu-main-"+i
					}
				})
				let otherMenuList = menuList.children.filter((item,index) => {
					return index >=4;
				})
				otherMenuList.forEach((item,i) => {
					let index = i%2;
					let temp = {
						"name":item.meta.title,
						"iconUrl":"../static/icons/"+item.meta.icon+".svg",
						"navigateTo":"../"+item.path,
						"className":"menu-sec-"+index
					};
					this.otherMenuList.unshift(temp);
				})
			},
			scanQrcode(){
				uni.scanCode({
					success: function (res) {
						console.log('条码类型：' + res.scanType);
						console.log('条码内容：' + res.result);
						qrcodeLogin(res.result).then(res=>{
							console.log(JSON.stringify(res))
						});
					}
				});
			}
		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		background-color: #F6F7F6;
	}

	.banner-content{
		width: 100%;
		height: 235px;
		position: relative;
		background-image: url("../static/images/index/banner.png");
		background-repeat: no-repeat;
		background-size: cover;
		text-align: center;
	}
	.header-title{
		font-family: 思源黑体;
		font-size: 20px;
		font-weight: 500;
		line-height: 20px;
		color: #ffffff;
		margin-top: 20px;
	}
	.banner-title{
		width: 334px;
		height: 94px;
		opacity: 1;
		margin-top: 34px;
	}
	.main-content{
		position: relative;
		top: -50px;
		width: 100%;
	}
	.menu-content{
		width: 90%;
		margin: 10px 5%;
		padding: 11px 15px;
		background-color: #ffffff;
		border-radius: 10px;
		text-align: center;
		display: flex;
		justify-content: space-around;
		align-items: center;
		flex-wrap: wrap;
		
	}
	.menu-cell{
		width: 22%;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}
	.menu-main{
		background: linear-gradient(180deg, #DDEAFF 0%, #E4F1FF 100%);
		padding: 15px;
		border-radius: 40px;
		width: 48px;
		height: 48px;
		margin-bottom: 10px;
	}
	.menu-main-1{
		background: linear-gradient(180deg, #E0F3FF 0%, #EBFCFF 100%);
	}
	.menu-main-2{
		background: linear-gradient(180deg, #FFEDDD 0%, #FFF7DB 100%);
	}
	.menu-main-3{
		background: linear-gradient(180deg, #E6E4FE 0%, #F1F0FF 100%);
	}
	.menu-main image{
		width: 18px;
		height: 18px;
	}
	.menu-cell text{
		font-family: 思源黑体;
		font-size: 13px;
		font-weight: 350;
		line-height: 16px;
		letter-spacing: 0px;
		
		color: #353B50;
	}
	.no-circle image{
		width: 18px;
		height: 18px;
		margin-top: 15px;
		margin-bottom: 10px;
	}
	.menu-sec-0{
		left: -20px; 
		filter: drop-shadow(20px 0 #F25432)
	}
	.menu-sec-1{
		left: -20px; 
		filter: drop-shadow(20px 0 #0BC5F4)
	}
	.section-content{
		width: 90%;
		background-color: #F6F7F6;
		margin: 0 5%;
	}
	.list-row{
		display: flex;
		align-items: flex-start;
		width: 100%;
	}
	.list-row image{
		width: 78px;
		height: 78px;
		margin-right: 5px;
	}
	.list-row-right{
		text-align: left;
		width: 75%;
	}
	.list-row-right .title{
		text-overflow: ellipsis;
		overflow: hidden;
		display: -webkit-box;			//特别显示模式
		-webkit-line-clamp: 2;			//行数
		line-clamp: 2;					
		-webkit-box-orient: vertical;
		margin-bottom: 10px;
	}
	.list-row-right text{
		font-size: 14px;
		font-weight: 350;
		line-height: 19px;
		
		color: #868996;
	}
</style>
